package com.eptok.weixin.action;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eptok.weixin.util.SignUtil;

import hikefa.core.global.GlobalCache;
import net.sf.json.JSONObject;
import yspay.express.store.WxStore;

/**
* 
*	TicketController类
*	作者：邓磊
*	时间：2016年7月4日 16:40:43
*	作用：提供票据信息
*	域：无
*
*/
@Controller
public class TicketController  extends BaseDispatchAction{
	
	
	@RequestMapping(value="/getTicket")
	public void getTicket(HttpServletResponse ros,HttpServletRequest res,String url)
	{
		String timestamp = Long.toString(System.currentTimeMillis() / 1000);
		String noncestr= WxStore.getToken();
		String jsapi_ticket = WxStore.getJsapiTicket();
		//组装
		String str = "jsapi_ticket=" + jsapi_ticket +
                "&noncestr=" + noncestr +
                "&timestamp=" + timestamp +
                "&url=" + url;
		
		
		try {
			String signature = SignUtil.sha1(str);
			
			Map map = new HashMap();
			map.put("timestamp", timestamp);
			map.put("appid", WxStore.getAppid());
			map.put("noncestr", noncestr);
			map.put("signature", signature);
			
			JSONObject json = JSONObject.fromObject(map);
			ros.setContentType("text/html;charset=UTF-8");
			PrintWriter out = ros.getWriter();
			out.write(json.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
